package LuoGu.模拟与高精度.魔法少女小Scarlet;

import java.io.StreamTokenizer;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int [][] ans = new int[510][510];
        int [][] temp = new int[510][510];
        int index = 1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                ans[i][j] = index++;
            }
        }
        int nn = s.nextInt();
        for(int i=0;i<nn;i++){
            int y = s.nextInt();
            int x = s.nextInt();
            int r = s.nextInt();
            int z = s.nextInt();
            if(z==0){
                for(int j=y-r;j<=y+r;j++){
                    for(int k=x-r;k<=x+r;k++){
                        temp[j][k] = ans[j][k];
                    }
                }
                for(int j=y-r;j<=y+r;j++){
                    for(int k=x-r;k<=x+r;k++){
                        //新坐标，y轴在变，x轴不变
                        //ans[k][2*x-j] = temp[j][k];
                        ans[y-x+k][x+y-j] = temp[j][k];
                    }
                }
            }else if(z==1){
                for(int j=x-r;j<=x+r;j++){
                    for(int k=y-r;k<=y+r;k++){
                        temp[j][k] = ans[j][k];
                    }
                }
                for(int j=x-r;j<=x+r;j++){
                    for(int k=y-r;k<=y+r;k++){
                        ans[y+x-k][x-y+j] = temp[j][k];
                    }
                }
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                System.out.print(ans[i][j]+" ");
            }
            System.out.println();
        }
    }
}
